package com.ninetyfour.app;

import android.util.Log;
import android.content.Context;
import io.flutter.app.FlutterApplication;
import java.util.Map;
import java.util.HashMap;
import com.umeng.commonsdk.UMConfigure; // ✅ 添加这一行
import com.qiyukf.unicorn.api.Unicorn;
import com.qiyukf.unicorn.api.YSFOptions;
import com.qiyukf.unicorn.api.YSFUserInfo;
import com.qiyukf.unicorn.api.ConsultSource;
import com.umeng.message.PushAgent;
import com.umeng.message.api.UPushRegisterCallback;
import com.umeng.analytics.MobclickAgent;


public class MainApplication extends FlutterApplication {
    private static final String TAG = "MainApplication";
    @Override
    public void onCreate() {
        super.onCreate();

        // 配置七鱼客服 SDK
        YSFOptions options = new YSFOptions();
        Unicorn.init(this, "8162eaea4e4fa01d3ad2777dcc335430", options, null);
        // 初始化友盟统计 SDK
        UMConfigure.init(getApplicationContext(), "684f73a179267e021085aed1", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "1b315f7ce61b4b345bbd9ca9952df492");
        // UMConfigure.setLogEnabled(true);
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);

    }

    // 打开客服页面的方法，并传递用户信息
    public void openCustomerService(Context context, String userId, String phone, String email, String version) {
        YSFUserInfo userInfo = new YSFUserInfo();
        userInfo.userId = userId;
        userInfo.data = "["
            + "{\"key\":\"real_name\", \"value\":\"" + userId + "\"},"
            + "{\"key\":\"mobile_phone\", \"hidden\":true, \"value\":\"" + phone + "\"},"
            + "{\"key\":\"email\", \"value\":\"" + email + "\"},"
            + "{\"key\":\"avatar\", \"value\":\"https://qiyukf.com/def_avatar.png\"},"
            + "{\"index\":0, \"key\":\"account\", \"label\":\"账号\", \"value\":\"zhangsan\", \"href\":\"http://example.domain/user/zhangsan\"},"
            + "{\"index\":1, \"key\":\"sex\", \"label\":\"性别\", \"value\":\"先生\"},"
            + "{\"index\":5, \"key\":\"reg_date\", \"label\":\"注册日期\", \"value\":\"2015-11-16\"},"
            + "{\"index\":6, \"key\":\"last_login\", \"label\":\"上次登录时间\", \"value\":\"2015-12-22 15:38:54\"}"
            + "]";
        
        // 设置用户信息
        Unicorn.setUserInfo(userInfo);

        ConsultSource source = new ConsultSource("https://qiyukf.com/", "Android" + version, "custom information string");

        // 打开七鱼客服页面
        Unicorn.openServiceActivity(context, "在线客服", source); // 使用传递的上下文
    }

    public void registerService(Context context) {
         // 初始化推送
        PushAgent mPushAgent = PushAgent.getInstance(getApplicationContext());

        // 注册推送，获取设备 Token
         mPushAgent.register(new UPushRegisterCallback() {
            @Override
            public void onSuccess(String deviceToken) {
                Log.i(TAG, "deviceTokensss: " + deviceToken);
            }

            @Override
            public void onFailure(String errCode, String errDesc) {
                Log.e(TAG, "register failed! " + "code:" + errCode + ",desc:" + errDesc);
            }
        });
    }
}
